﻿Imports System.IO
Public Class Log
    Public Event NewMessage(message As String)

    Public Sub AddEntry(message As String)
        Try
            Dim sw As New StreamWriter(System.AppDomain.CurrentDomain.BaseDirectory() + "\Log.txt", True)
            sw.WriteLine(DateTime.UtcNow.ToString + ": " + message.ToString)
            sw.Flush()
            sw.Close()
            RaiseEvent NewMessage(message)
        Catch : End Try
    End Sub

    Public Function GetLog() As String
        Try
            Dim sr As New StreamReader(System.AppDomain.CurrentDomain.BaseDirectory() + "\Log.txt", True)
            Dim output = sr.ReadToEnd
            sr.Close()
            Return output
        Catch : End Try
        Return ""
    End Function

    Public Shared Sub AddError(message As String)
        Try
            Dim sw As New StreamWriter(System.AppDomain.CurrentDomain.BaseDirectory() + "\Log.txt", True)
            sw.WriteLine(DateTime.UtcNow.ToString + ": " + message.ToString)
            sw.Flush()
            sw.Close()
        Catch : End Try
    End Sub
End Class
